const argv = require('minimist')(process.argv.slice(2))
const iconv = require("iconv-lite")
const spawn = require("child_process").spawn
const path = require('path')
const readline = require('readline')

const runCmd = argv._[0]
const project = argv.project

const processObj = spawn('npm', ['run', runCmd], {
  cwd: path.resolve(__dirname, project),
  shell: process.platform === 'win32'
});

processObj.stdout.on("data", (thunk) => {
  console.log(iconv.decode(thunk, "gbk"));
})
processObj.stderr.on("data", (data) => {
  console.log(data.toString())
})
processObj.on("close", (code) => {
  console.log(code.toString());
})
processObj.on("exit", (code) => {
  console.log(code.toString());
})
